FROM registry.cn-hangzhou.aliyuncs.com/lerry-xia/jdk:21

ENV JAVA_HOME=/opt/java/jdk21 \
    PATH=${JAVA_HOME}/bin:${PATH} \
    TZ=Asia/Shanghai \
    LANG=C.UTF-8

# 应用相关变量（单独分组管理）
ENV ENV_MODE=dev \
    PROJECT_NAME=Jole \
    APP_NAME=Jole-gateway \
    APP_VERSION=1.0.0 \
    JVM_MEM_OPTS="-Xms256m -Xmx256m -Xmn256m" \
    JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError"

LABEL author="lerryxia" \
      maintainer="lerryxia@foxmail.com" \
      app.name="${APP_NAME}" \
      app.version="${APP_VERSION}" \
      description="Jole gateway service container"

RUN set -eux; \
    mkdir -p /opt/jole/{logs,config}; \
    if [ -d "/var/cache/apk" ]; then rm -rf /var/cache/apk/*; \
    elif [ -d "/var/lib/apt/lists" ]; then rm -rf /var/lib/apt/lists/*; fi

WORKDIR /opt/jole/

COPY target/Jole-gateway.jar app.jar

# 检查JAR包是否复制成功
RUN if [ ! -f "app.jar" ]; then \
        echo "Error: app.jar not found!"; \
        exit 1; \
    fi


VOLUME ["/opt/jole/logs", "/opt/jole/config"]

EXPOSE 9999

ENTRYPOINT ["sh", "-c", "trap 'kill -TERM $PID' TERM INT; java $JAVA_OPTS -Dspring.profiles.active=$ENV_MODE -jar app.jar & PID=$!; wait $PID; exit $?"]
